<%--@elvariable id="curPage" type="com.red.servlet.house.HouseQueryServlet"--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: HP
  Date: 2021/11/16
  Time: 17:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
	<title>Title</title>
	<%
		pageContext.setAttribute("APP_PATH", request.getContextPath());
	%>
	<link href="${APP_PATH}/static/bootstrap-3.4.1-dist/css/bootstrap.min.css" rel="stylesheet">
	<link href="${APP_PATH}/static/css/common_style.css" rel="stylesheet">
	<link href="${APP_PATH}/static/css/index.css" rel="stylesheet">
</head>
<body>
<div class="container landing main">
	<div class="row">
		<%--@elvariable id="queryResult" type="com.red.servlet.house.HouseQueryServlet"--%>
		<c:forEach items="${queryResult}" var="house">
			<div class="col-sm-6 col-md-3">
				<div class="house">
					<a class="thumbnail col-lg-12">
						<c:if test="${empty house.picture}">
							<img src="${APP_PATH}/static/img/default.jpg" alt="图片">
						</c:if>
						<c:if test="${!(empty house.picture)}">
							<img src="${APP_PATH}/static/${house.picture}" alt="图片">
						</c:if>
					</a>
					<div class="caption col-lg-12">
						<h3>${house.house_name}</h3>
						<c:if test="${empty house.description}">
							<p>这间屋子还没有描述</p>
						</c:if>
						<c:if test="${!(empty house.description)}">
							<p>${house.description}</p>
						</c:if>
						<div class="row">
							<div class="col-xs-6"><h4>${house.price}/月</h4></div>
							<div class="col-xs-6">
								<c:if test="${!(empty user)}">
									<c:if test="${user.uLevel != 3}">
										<c:if test="${house.status == '洽谈中'}">
											<button onclick="reserve(${house.house_id})"
													class="btn btn-danger btn-lg btn-block" role="button">抢房
											</button>
										</c:if>
										<c:if test="${!(house.status == '洽谈中')}">
											<button
													class="btn btn-primary btn-lg btn-block" role="button"
													onclick="reserve(${house.house_id})">预定
											</button>
										</c:if>
									</c:if>
								</c:if>
							</div>
						</div>
					</div>
				</div>
			</div>
		</c:forEach>
	</div>
</div>
<hr/>
<%--@elvariable id="pageInfo" type="java.util.Map"--%>
<nav aria-label="...">
	<ul class="pager">
		<c:if test="${!(pageInfo.curPage-1 <=0)}">
			<li>
				<a class="btn btn-lg" href="houseQuery?mode=1&page=${pageInfo.curPage-1}">
					<span class="glyphicon glyphicon-chevron-left">后退</span>
				</a>
			</li>
		</c:if>
		<c:if test="${!(empty queryResult)}">
			<li><a class="btn btn-lg" href="houseQuery?mode=1&page=${pageInfo.curPage+1}">前进<span
					class="glyphicon glyphicon-chevron-right"></span></a>
			</li>
		</c:if>
	</ul>
</nav>
</body>
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"
		integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ"
		crossorigin="anonymous"></script>
<script src="${APP_PATH}/static/bootstrap-3.4.1-dist/js/bootstrap.min.js"></script>
<script>
    function reserve(hid) {
        $.ajax({
            url: "${APP_PATH}/addOrder",
            type: 'POST',
            dataType: 'text',
            data: {
                id: hid,
            },
            success: function (data) {
                alert(data)
                location.reload()
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.responseText)
            }
        });
    }

</script>
</html>
